.PHONY: build docker-build docker-extract clean

# 默认目标
all: docker-build docker-extract

# 本地构建项目
build:
	@echo "正在本地构建项目..."
	dotnet restore
	dotnet publish -c Release -o out

# 使用Docker构建项目
docker-build:
	@echo "正在使用Docker构建项目..."
	docker build -t ctyun-cf-sdk .

# 从Docker容器中提取编译好的应用程序
docker-extract:
	@echo "正在从Docker容器中提取编译好的应用程序..."
	docker create --name temp-container ctyun-cf-sdk
	if not exist publish mkdir publish
	docker cp temp-container:/app/. ./publish/
	docker rm temp-container
	@echo "应用程序已提取到publish目录"

# 运行Docker容器
docker-run:
	@echo "正在运行Docker容器..."
	docker run --name ctyun-cf-sdk-container ctyun-cf-sdk
	
# 清理构建产物
clean:
	@echo "正在清理..."
	dotnet clean
	if exist out rmdir /s /q out
	if exist publish rmdir /s /q publish
	docker rm -f temp-container 2>nul || true
	docker rm -f ctyun-cf-sdk-container 2>nul || true